library Wave18b initializer init requires LegacySystem, EndCinematics

    private function EnableMOSSelection takes nothing returns nothing
        local integer i = 1
        local integer i3
        if udg_DMDeliveryTime[101]<1337.0 then
            set udg_DMDeliveryTime[101] = 1337.0
            //call EnableTrigger(gg_trg_ShowStats)
            call PolledWait(5.)
            set i3=1
            loop
                exitwhen i3>udg_InitialPlayers
                
                set i3=i3+1
            endloop
        endif
    endfunction
	
    private function EchoCompany takes nothing returns boolean
        local integer i=1
        loop
            exitwhen i>udg_Players
            if GetFilterUnit()==udg_Hero[udg_Sorted[i]] then
                return true
            endif
            set i=i+1
        endloop
        return false
    endfunction

    private function NuclearStrike takes nothing returns nothing
        call ALICEText(5.0, "|cff8b864eObjective Failed|r : Nuclear Launch Detected." )
        call PolledWait(5.)
        call GeneralText(5.0, "|cffcd950cIron Hand|r : God help us all." )
        call PolledWait(5.)
        call StartSound(gg_snd_F22Rocket)
        call PolledWait(10.)
        call PauseAllUnitsBJ(true)
        call ClearTextMessages()
        call CinematicFadeBJ( bj_CINEFADETYPE_FADEOUT, 2.0, "ReplaceableTextures\\CameraMasks\\Black_mask.blp", 0, 0, 0, 0 )
        call StartSound(gg_snd_Shiva)
        call UnitDamagePoint(udg_Residence41,0,9000.0,2000.0,5360.0,125000.0,true,false,ATTACK_TYPE_SIEGE,DAMAGE_TYPE_DEMOLITION,WEAPON_TYPE_WHOKNOWS)
        call PolledWait(5.)
        call StartSound(gg_snd_ShivaMeltdown)
        call PolledWait(10.)
        call ClearTextMessages()
        set udg_soundpath = "Sound\\Music\\mp3Music\\OrcDefeat.mp3"
        call PolledWait(10.)
        call DisplayTimedTextToPlayer(GetLocalPlayer(),0.0,0.0,30.0, "Boston now lies in smoldering ruins. The outbreak continues to spread beyond the state." )
        call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 7.0, " " )
        call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 7.0, " " )
    endfunction


    private function GolfCompany takes nothing returns boolean
        return GetOwningPlayer(GetFilterUnit())==Player(13) and GetUnitPointValue(GetFilterUnit())!=5
    endfunction

    private function Wave18b takes nothing returns nothing //Assault on Ravenholm
        local group g
        local group g2
        local integer i=1
        local integer countdown=1
        local integer xp
        local location l = Location(-722.0,-130.0)
        set udg_CurrentWave = 18
        call GenericActions.execute()
        call GeneralText(5.0, "|cffcd950cMarine|r : We've got to make an assault on Ravenholm now." )
        call StartSound(gg_snd_RavenholmAssault)
        call MultiboardSetTitleText( udg_SquadStatus, "Reclaim Nuclear Facilities" )
        call MBSet( udg_SquadStatus, 1, 1, "Objective : Reclaim Nuclear Facilities" )
        call QuestSetDescription(udg_CurrentOrders, "Reclaim Nuclear Facilities. Assault Ravenholm and eliminate all hostile presence before Golf Company launches a nuclear strike." )
        call ALICEText(5.0, "|cff8b864eNew Objective|r : Reclaim Nuclear Facilities." )
        call GankMarine(Player(9),'z009',4+GetRandomInt(1,udg_Spawn),3000,5000)
        if GetRandomInt(0,5)==1 and udg_InitialPlayers>3 and udg_SquadXP>135000 then
            call RandomSpawn2('h001',1,1) //Apache
        endif
        call GankMarine(Player(9),'z009',2+GetRandomInt(1,udg_Spawn),3000,5000)
        call GeneralText(5.0, "|cffcd950cIron Hand|r : We have five more minutes before launch. Move in quick!" )
        call PolledWait(10.*udg_Pace)
        call ALICEText(5.0, "|cffcd950cALICE|r : Incoming Communications." )
        call PolledWait(5.*udg_Pace)
        call GeneralText(5.0, "|cffcd950cCapt. Barnes|r : Get out of here while you still can. We don't need to lose anymore good men." )
        call PolledWait(7.)
        call GeneralText(5.0, "|cffcd950cMarine|r : We won't let you take the entire state out. There are still survivors out there." )
        call PolledWait(5.)
        call GeneralText(5.0, "|cffcd950cCapt. Barnes|r : You've been misled. I was in Boston myself a two days ago. I know." )
        loop
            exitwhen udg_SectorClear or countdown>=5
            set g = AMGetUnitsInRange(1750,l,Condition(function GolfCompany))
            set g2 = AMGetUnitsInRange(1750,l,Condition(function EchoCompany))
            if FirstOfGroup(g)==null and FirstOfGroup(g2)!=null then
                set udg_SectorClear=true
				call SetMOSEnabled(true)
                if (udg_Mode==1 or udg_Mode==4) and udg_Players>0 then
                    call ALICE2Text(10.0, "Nuclear Facilities Secure. |cff1e90ff400 XP|r awarded to all Marines." )
                    set i=1
                    loop
                        exitwhen i>udg_InitialPlayers
                        if GetPlayerSlotState(ConvertedPlayer(udg_Sorted[i]))!=PLAYER_SLOT_STATE_LEFT then
                            set udg_Experience[udg_Sorted[i]] = udg_Experience[udg_Sorted[i]] + 400
                        endif
                        set i=i+1
                    endloop
                endif
                exitwhen 1==1
            endif
            call DestroyGroup(g)
            call DestroyGroup(g2)
            call PolledWait(52.)
            if udg_SectorClear==false then
                call GankMarine(Player(9),'z008',GetRandomInt(1,udg_Spawn),2900,4500)
                call GankMarine(Player(9),'z009',GetRandomInt(1,udg_Spawn),2900,4500)
                call PolledWait(5.)
                call GankMarine(Player(9),'z008',2+GetRandomInt(1,udg_Spawn),2900,4500)
            endif
            set countdown=countdown+1
        endloop
        if countdown>=5 then
            call NuclearStrike.execute()
            return
        endif
        call PolledWait(5.)
        set i=1
        if udg_Mode==1 and udg_Players>5 and udg_InitialPlayers==udg_Players then
            if udg_Difficulty==5 then
                set xp = 500
            else
                set xp = 250
            endif
            call ALICE2Text(10.0, "Zero casualties. |cff1e90ff" + I2S(xp) + " XP|r awarded to all Marines." )
            loop
                exitwhen i>udg_InitialPlayers
                if GetPlayerSlotState(ConvertedPlayer(udg_Sorted[i]))!=PLAYER_SLOT_STATE_LEFT then
                    set udg_Experience[udg_Sorted[i]] = udg_Experience[udg_Sorted[i]] + xp
                endif
                set i=i+1
            endloop
        endif
        call PolledWait(10.)
        call GeneralText(5.0, "|cffcd950cIron Hand|r : It's been a long day. Time to head back home. Charlie Company will take over battlefield sanitation." )
        call PolledWait(7.)
        call GeneralText(5.0, "|cffcd950cIron Hand|r : This fiasco is going to be a mess to explain." )
        call PolledWait(5.)
        call GeneralText(5.0, "|cffcd950cMarine|r : Let's worry about that later. You still have that hot chow waiting for me?" )
        call PolledWait(25.)
        call SetForceAllianceStateBJ(bj_FORCE_PLAYER[9], udg_EchoCompany,bj_ALLIANCE_ALLIED)
        call SetForceAllianceStateBJ(udg_EchoCompany, bj_FORCE_PLAYER[9],bj_ALLIANCE_ALLIED)
        call SetForceAllianceStateBJ(bj_FORCE_PLAYER[11], udg_EchoCompany,bj_ALLIANCE_ALLIED)
        call SetForceAllianceStateBJ(udg_EchoCompany, bj_FORCE_PLAYER[11],bj_ALLIANCE_ALLIED)
        call SetForceAllianceStateBJ(bj_FORCE_PLAYER[13], GetPlayersAllies(Player(0)),bj_ALLIANCE_UNALLIED)
        call SetForceAllianceStateBJ(GetPlayersAllies(Player(0)), bj_FORCE_PLAYER[13],bj_ALLIANCE_UNALLIED)
        call SetForceAllianceStateBJ(bj_FORCE_PLAYER[13], bj_FORCE_PLAYER[9],bj_ALLIANCE_UNALLIED)
        call SetForceAllianceStateBJ(bj_FORCE_PLAYER[9], bj_FORCE_PLAYER[13],bj_ALLIANCE_UNALLIED)
        call SetForceAllianceStateBJ(bj_FORCE_PLAYER[13], bj_FORCE_PLAYER[11],bj_ALLIANCE_UNALLIED)
        call SetForceAllianceStateBJ(bj_FORCE_PLAYER[11], bj_FORCE_PLAYER[13],bj_ALLIANCE_UNALLIED)
        call SetForceAllianceStateBJ(bj_FORCE_PLAYER[14], bj_FORCE_PLAYER[9],bj_ALLIANCE_UNALLIED)
        call SetForceAllianceStateBJ(bj_FORCE_PLAYER[9], bj_FORCE_PLAYER[14],bj_ALLIANCE_UNALLIED)
        call SetForceAllianceStateBJ(bj_FORCE_PLAYER[14], bj_FORCE_PLAYER[11],bj_ALLIANCE_UNALLIED)
        call SetForceAllianceStateBJ(bj_FORCE_PLAYER[11], bj_FORCE_PLAYER[14],bj_ALLIANCE_UNALLIED)
        call SetForceAllianceStateBJ(bj_FORCE_PLAYER[13], bj_FORCE_PLAYER[14],bj_ALLIANCE_ALLIED_VISION)
        call SetForceAllianceStateBJ(bj_FORCE_PLAYER[14], bj_FORCE_PLAYER[13],bj_ALLIANCE_ALLIED_VISION)
        call EnableMOSSelection.execute()
        if GetRandomInt(0,2)==1 then
            call EndSequenceA.execute()
        else
            call EndSequenceD.execute()
        endif
        set g=null
        set g2=null
        call RemoveLocation(l)
        set l=null
    endfunction


    private function init takes nothing returns nothing
        call RegisterFunction("Wave18b", function Wave18b)
    endfunction
    
endlibrary
